package com.hxzy.system.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxzy.common.core.domain.entity.SysDictData;

import com.hxzy.common.utils.DictUtils;
import com.hxzy.system.domain.dto.DictDataSearchDTO;
import com.hxzy.system.mapper.SysDictDataMapper;
import com.hxzy.system.service.ISysDictDataService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 64689
 */
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService {


    @Override
    public IPage<SysDictData> selectDictDataList(DictDataSearchDTO dictData) {
        Page<SysDictData> of = PageDTO.of(1, 10);
        return this.baseMapper.selectDictDataList(of, dictData);
    }

    /**
     * 根据字典数据ID查询信息
     *
     * @param dictCode 字典数据ID
     * @return 字典数据
     */

    @Override
    public SysDictData selectDictDataById(Long dictCode) {
        return this.baseMapper.selectDictDataById(dictCode);
    }

    @Override
    public List<SysDictData> selectDictDataByType(String dictType) {
        return this.baseMapper.selectDictDataByType(dictType);
    }

    @Override
    public boolean updateBy(SysDictData dict) {
        return this.baseMapper.updateBy(dict);
    }

    @Override
    public int deleteDictDataByIds(Long[] dictCodes) {
        int row = this.baseMapper.deleteDictDataByIds(dictCodes);
        if (row > 0) {
            DictUtils.clearDictCache();
        }
        return row;
    }

    @Override
    public boolean insert(SysDictData dict) {
        int insert = this.baseMapper.insert(dict);
        if(insert>0){
            return true;
        }
        return false;
    }
}
